Add lastError function#3654
Conversation
| e(x,p1,h1) | ||
| f(x,p1,h1) | ||
| g(x,p1,h1) | ||
| assert((last try 1/0 else lastError()) == "division by zero") |
There was a problem hiding this comment.
Are you planning on replacing the manual tests above with automatic versions?
|
I did something similar on my dev branch. I'll compare the code. |
There was a problem hiding this comment.
not directly related, but do you know what these two lines are for:
Lines 307 to 308 in 3fc8759
There was a problem hiding this comment.
No idea! They don't appeared to be used anywhere.
|
here are AFAICT the main differences I find between your implementation and mine:
|
One of the big goals was to find out if there was an error without actually raising one, e.g., That being said, @MichaelABurr has some code updating it during
That was our original idea, but we didn't realize it was possible. Most of the global variables like this (e.g., Is your code live on Macaulay2Web? Or just in a branch somewhere? |
|
good point. maybe I'm wrong about updating it when it's printed, as you said, the main goal is to test the error message with |
|
the relevant commit seems to be 74e022a |
|
I still think having a global variable is marginally simpler than a function. |
|
It might be nice to have something another variable to remember the value of |
commit message for your changes. Lines starting
Mutable so can be cleared by assigning null
|
I've rewritten this a bit so that i1 : 1/0
stdio:1:1:(3): error: division by zero
i2 : lastError
o2 = (stdio:1:0-1:3, division by zero)
o2 : Sequence
i3 : lastError = null |
| printErrorMessage(tryToken," ... to match this 'try'"); | ||
| return errorTree); | ||
| makeParseError(elseToken,"syntax error : expected 'else'"); | ||
| return makeParseError(tryToken," ... to match this 'try'")); |
There was a problem hiding this comment.
just curious, what's the meaning of these changes?
There was a problem hiding this comment.
I added a few constructors for lower-level lexing and parsing errors that set lastError in these cases.
This returns a sequence containing the location and message string for the last error (at least most of the time, e.g., not for syntax errors).
The eventual goal is to use this in the MPI package (see #2129) for handling errors gracefully, e.g., doing something like
try x else lastError().